package com.uchengwang.ui.cm_ui.rychat.msgtype;

import android.content.Context;
import android.text.Spannable;
import android.text.SpannableString;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.uchengwang.R;
import com.uchengwang.functions.image.ImageManager;
import com.uchengwang.ui.cm_ui.rychat.bean.BigEmojicon;
import com.uchengwang.ui.cm_ui.rychat.utils.BigEmojiconData;
import com.zhy.autolayout.utils.AutoUtils;

import io.rong.imkit.model.ProviderTag;
import io.rong.imkit.model.UIMessage;
import io.rong.imkit.widget.provider.IContainerItemProvider;
import io.rong.imlib.model.Message;

/**
 * Created by U城网 on 2017/10/20.
 */

@ProviderTag(
        messageContent = BigEmoMessage.class,
        showProgress = false,
        showReadState = true
)
public class BigEmotionItemProvider extends IContainerItemProvider.MessageProvider<BigEmoMessage>  {

    private static final String TAG = "BigEmotionItemProvider";

    public BigEmotionItemProvider() {
    }

    public View newView(Context context, ViewGroup group) {
        View view = LayoutInflater.from(context).inflate(R.layout.layout_ry_big_emotion_item, (ViewGroup)null);
        BigEmotionItemProvider.ViewHolder holder = new BigEmotionItemProvider.ViewHolder();
        holder.img = (ImageView) view.findViewById(R.id.rc_img);
        view.setTag(holder);
        AutoUtils.autoSize(view);
        return view;
    }

    public void onItemClick(View view, int position, BigEmoMessage content, UIMessage message) {

    }

    public void bindView(View v, int position, BigEmoMessage content, UIMessage message) {
        if (content ==null){
            return;
        }
        BigEmotionItemProvider.ViewHolder holder = (BigEmotionItemProvider.ViewHolder)v.getTag();
        BigEmojicon emojicon = BigEmojiconData.getEaseEmotion(content.getBigCodeId());

        if(message.getMessageDirection() == Message.MessageDirection.SEND) {//自己发送的
//            v.setBackgroundResource(R.drawable.rc_ic_bubble_right);
            ImageManager.getInstance().loadImage(v.getContext(), holder.img, emojicon.getBigIconSelf(), ImageManager.ImageType.NARMOL);
        } else {
//            v.setBackgroundResource(R.drawable.rc_ic_bubble_left);
            ImageManager.getInstance().loadImage(v.getContext(), holder.img, emojicon.getBigIcon(), ImageManager.ImageType.NARMOL);
        }

    }

    public Spannable getContentSummary(BigEmoMessage data) {
        return new SpannableString("["+data.getBigName()+"]");
    }


    private static class ViewHolder {
        private ImageView img;
    }
}
